package com.yang.test.controller;

import com.yang.test.domain.DTO.ResultRequest;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.QuestionH;
import com.yang.test.service.HldzyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class HldzyController {
    
    @Autowired
    private HldzyService hldzyService;
    
    /**
     * 获取所有测试题目
     */
    @GetMapping("/questionsH")
    public Map<String, Object> getAllQuestions() {
        List<QuestionH> questions = hldzyService.getAllQuestions();
        Collections.shuffle(questions); // 随机排序问题
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 0);
        response.put("message", "success");
        response.put("data", questions);
        
        return response;
    }
    
    /**
     * 提交测试结果并获取分析
     */
    @PostMapping("/results")
    public Map<String, Object> submitResult(@RequestBody ResultRequest request) {
        ResultResponse result = hldzyService.calculateResult(request.getAnswers());
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 0);
        response.put("message", "success");
        response.put("data", result);
        
        return response;
    }
}